package base;
import java.util.Scanner;

public class 航空ticket {
    public static void main(String[] args) {
        /*机票价格按照淡季旺季、头等舱和经济舱收费、输入机票原价、月份和头等舱或经济舱。
        按照如下规则计算机票价格:旺季(5-10月)头等舱9折，经济舱8,5折，淡季(11月到来年4月)头等舱7折，经济舱6.5折。*/

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入当前月份：");
        int month = sc.nextInt();
        System.out.println("请输入原机票价格：");
        int ticket = sc.nextInt();
        System.out.println("请输入订购类型(头等舱为0，经济舱为1):");
        int seat = sc.nextInt();

        while (true){
            if (month >= 5 && month <= 10) {
                ticket = geticket(seat, ticket, 0.9, 0.85);
            } else if ((month >= 11 && month <= 12) || (month >= 1 && month <= 4)) {
                ticket = geticket(seat, ticket, 0.7, 0.65);
            } else {
                System.out.println("抱歉！月份不合法》");
                System.out.println("请重新输入当前月份：");
                month = sc.nextInt();
                continue;
            }
            System.out.println("机票价格为：" + ticket);break;
        }
//        if (month >= 5 && month <= 10) {
//            ticket = geticket(seat, ticket, 0.9, 0.85);
//        } else if ((month >= 11 && month <= 12) || (month >= 1 && month <= 4)) {
//            ticket = geticket(seat, ticket, 0.7, 0.65);
//        } else {
//            System.out.println("抱歉！月份不合法》");
//        }
//        System.out.println("机票价格为：" + ticket);
    }

    public static int geticket(int seat, int ticket, double x, double x1) {
        int t = ticket;
        while(true) {
            if (seat == 0) {
                t = (int) (t * x);break;
            } else if (seat == 1) {
                t = (int) (t * x1);break;
            } else {
                System.out.println("抱歉！舱位类型不存在》");
                Scanner sc = new Scanner(System.in);
                System.out.println("请重新输入订购类型(头等舱为0，经济舱为1):");
                seat = sc.nextInt();
                continue;
            }
        }
        return t;
    }
}
